package com.payment.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.payment.common.annotation.Log;
import com.payment.common.enums.BusinessType;
import com.payment.system.domain.SystemConfig;
import com.payment.system.service.ISystemConfigService;
import com.payment.framework.web.base.BaseController;
import com.payment.common.page.TableDataInfo;
import com.payment.common.base.AjaxResult;
import com.payment.common.utils.ExcelUtil;

/**
 * 全局配置 信息操作处理
 * 
 * @author payment
 * @date 2019-01-05
 */
@Controller
@RequestMapping("/system/systemConfig")
public class SystemConfigController extends BaseController
{
    private String prefix = "system/systemConfig";
	
	@Autowired
	private ISystemConfigService systemConfigService;
	
	@RequiresPermissions("system:systemConfig:view")
	@GetMapping()
	public String systemConfig()
	{
	    return prefix + "/systemConfig";
	}
	
	/**
	 * 查询全局配置列表
	 */
	@RequiresPermissions("system:systemConfig:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SystemConfig systemConfig)
	{
		startPage();
        List<SystemConfig> list = systemConfigService.selectSystemConfigList(systemConfig);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出全局配置列表
	 */
	@RequiresPermissions("system:systemConfig:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SystemConfig systemConfig)
    {
    	List<SystemConfig> list = systemConfigService.selectSystemConfigList(systemConfig);
        ExcelUtil<SystemConfig> util = new ExcelUtil<SystemConfig>(SystemConfig.class);
        return util.exportExcel(list, "systemConfig");
    }
	
	/**
	 * 新增全局配置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存全局配置
	 */
	@RequiresPermissions("system:systemConfig:add")
	@Log(title = "全局配置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SystemConfig systemConfig)
	{		
		return toAjax(systemConfigService.insertSystemConfig(systemConfig));
	}

	/**
	 * 修改全局配置
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		SystemConfig systemConfig = systemConfigService.selectSystemConfigById(id);
		mmap.put("systemConfig", systemConfig);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存全局配置
	 */
	@RequiresPermissions("system:systemConfig:edit")
	@Log(title = "全局配置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SystemConfig systemConfig)
	{		
		return toAjax(systemConfigService.updateSystemConfig(systemConfig));
	}
	
	/**
	 * 删除全局配置
	 */
	@RequiresPermissions("system:systemConfig:remove")
	@Log(title = "全局配置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(systemConfigService.deleteSystemConfigByIds(ids));
	}
	
}
